package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    @Insert("insert into orders (number, user_id, address_book_id, consignee, phone, delivery_status, estimated_delivery_time, pack_amount, amount, remark, tableware_number, tableware_status, status, order_time, pay_status,address) " +
            " values (#{number},#{userId},#{addressBookId},#{consignee},#{phone},#{deliveryStatus},#{estimatedDeliveryTime},#{packAmount},#{amount},#{remark},#{tablewareNumber},#{tablewareStatus},#{status},#{orderTime},#{payStatus},#{address})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void insert(Orders orders);
    /**
     * 分页查询
     * @return
     */
    List<Orders> selectHistoryOrders(Long userId, Integer status);
    /**
     * 查看订单详情
     * @param id
     * @return
     */
    Orders selectByOrderId(Long id);
    /**
     * 取消订单
     * @param orders
     */
    void updateById(Orders orders);

    /**
     * 订单搜索
     * @param queryDTO
     * @return
     */
    List<OrderVO> selectSearch(OrdersPageQueryDTO queryDTO);

    /**
     * 查询各个状态的订单
     * @param status
     * @return
     */
    Integer selectStatistics(Integer status);

    /**
     * 1.1营业额统计
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    Double turnoverStatistics(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    /**
     * 订单统计
     * @param beginTime
     * @param endTime
     * @return
     */
    Integer count(LocalDateTime beginTime, LocalDateTime endTime,Integer status);

    /**
     * top10订单
     * @param beginTime
     * @param endTime
     * @return
     */
    List<GoodsSalesDTO> top10(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 1.2营业额查询
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     *根据动态条件统计订单数量
     * @param map
     */
    Integer countByMap(Map map);

    /**
     * 查询商品销量排名
     * @param begin
     * @param end
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
//    Integer countByMap(HashMap map);

}
